// pages/my/my/index.js
const app = getApp()
const db = wx.cloud.database()
const OPENID = wx.getStorageSync('userOpenid').OPENID
const IdentityStatu = wx.getStorageSync('identityStatu')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    myresumUrl: '',
    isIdentity: true,
    identity: {
      name: "",
      tagColor: "yellow"
    },
    userInfo: {
      tagColor: "yellow",
      phone: "17589458896",
      address: "茂南区广东石油化工学院",
      wx: "17589458896",
    }
  },

  onLoad: function (options) {
    var tableName

    if (IdentityStatu == 1) {
      tableName = "usersData"
      this.setData({
        identity: {
          name: "求职者",
          tagColor: "green"
        },
        myresumUrl: "/pages/my/myResume/myResume"
      })
    } else if (IdentityStatu == 2) {
      tableName = "shopmanData"
      this.setData({
        identity: {
          name: "招聘者",
          tagColor: "yellow"
        },
        isIdentity: false,
        myresumUrl: "/pages/my/myResume/shopResume"
      })
    }

    db.collection(tableName).where({
      _openid: OPENID
    })
      .field({
        email: true,
        experience: true,
        phone: true,
      })
      .get({
        success: res => {
          console.log(res.data)
          this.setData({
            userInfo: res.data[0]
          })
        }
      })
  },

  logout: function (e) {
    wx.clearStorageSync()
    wx.showToast({
      title: "成功消理缓存",
      icon: 'success',
      duration: 2000
    })
  }

})